package com.blog.controller.admin;

import com.blog.commons.constant.ControllerConstant;
import com.blog.commons.web.base.BaseController;
import com.blog.commons.web.domain.request.PageDomain;
import com.blog.commons.web.domain.response.PageResult;
import com.blog.commons.web.domain.response.Result;
import com.blog.pojo.TbBlog;
import com.blog.pojo.TbBlogLog;
import com.blog.service.LogService;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: dal-blog
 * @description: 日志操作
 * @author: jian
 * @create: 2022-01-28 22:18
 **/
@Log4j2
@Controller
@RequestMapping(ControllerConstant.API_ADMIN_PREFIX+"/log")
public class LogController extends BaseController {

    public static String MODULE_PATH = "/admin/log/";

    @Resource
    private LogService logService;

    @GetMapping("toLogList")
    public ModelAndView toLoginList() {
        return jumpPage(MODULE_PATH + "log");
    }

    /**
     * 分页查询所有日志
     * @param domain
     * @return
     */
    @ResponseBody
    @GetMapping("logList")
    public Result articleList(PageDomain domain,
                               TbBlogLog blogLog) {
        log.info("分页查询日志列表的入参为==========>>>>[{},{},{}]", domain.getPage(), domain.getLimit(), blogLog);try {
            PageResult<TbBlogLog> byPage = logService.findByPage(domain, blogLog);
            Long total = byPage.getTotal();
            List<TbBlogLog> content = byPage.getData();
            Result result = new Result(0, "成功", total.intValue(), content);
            return result;
        } catch (Exception e) {
            log.error("查询日志列表异常==============", e);
            return Result.error("查询日志列表失败");
        }
    }

}
